/**
 * 面试相关API
 */
import { request } from '@/utils/request'

// 面试申请相关API
export const interviewApplicationApi = {
  // 获取面试申请列表
  getApplicationList(params = {}) {
    return request.get('/interviews/applications/', params)
  },

  // 创建面试申请
  createApplication(data) {
    return request.post('/interviews/applications/', data)
  },

  // 获取面试申请详情
  getApplicationDetail(id) {
    return request.get(`/interviews/applications/${id}/`)
  },

  // 更新面试申请
  updateApplication(id, data) {
    return request.patch(`/interviews/applications/${id}/`, data)
  },

  // 删除面试申请
  deleteApplication(id) {
    return request.delete(`/interviews/applications/${id}/`)
  },

  // 审核面试申请（老师用）
  reviewApplication(id, data) {
    return request.post(`/interviews/applications/${id}/review/`, data)
  }
}

// 面试记录相关API
export const interviewApi = {
  // 获取面试列表
  getInterviewList(params = {}) {
    return request.get('/interviews/interviews/', params)
  },

  // 获取面试详情
  getInterviewDetail(id) {
    return request.get(`/interviews/interviews/${id}/`)
  },

  // 开始面试
  startInterview(id) {
    return request.post(`/interviews/interviews/${id}/start/`)
  },

  // 完成面试
  completeInterview(id) {
    return request.post(`/interviews/interviews/${id}/complete/`)
  },

  // 获取面试结果
  getInterviewResult(id) {
    return request.get(`/interviews/interviews/${id}/result/`)
  },

  // 获取面试安排（日历视图）
  getInterviewSchedule(params = {}) {
    return request.get('/interviews/interviews/schedule/', params)
  }
}

// 面试结果相关API
export const interviewResultApi = {
  // 获取面试结果列表
  getResultList(params = {}) {
    return request.get('/interviews/results/', params)
  },

  // 获取面试结果详情
  getResultDetail(id) {
    return request.get(`/interviews/results/${id}/`)
  },

  // 老师提交面试结果
  teacherSubmitResult(id, data) {
    return request.post(`/interviews/results/${id}/teacher_submit/`, data)
  },

  // 学生提交面试反馈
  studentSubmitResult(id, data) {
    return request.post(`/interviews/results/${id}/student_submit/`, data)
  }
}

// 面试分类相关API
export const interviewCategoryApi = {
  // 获取面试分类列表
  getCategoryList() {
    return request.get('/interviews/categories/')
  }
}

// 面试题目相关API
export const interviewQuestionApi = {
  // 获取面试题目列表
  getQuestionList(params = {}) {
    return request.get('/interviews/questions/', params)
  },

  // 创建面试题目
  createQuestion(data) {
    return request.post('/interviews/questions/', data)
  },

  // 获取面试题目详情
  getQuestionDetail(id) {
    return request.get(`/interviews/questions/${id}/`)
  },

  // 更新面试题目
  updateQuestion(id, data) {
    return request.patch(`/interviews/questions/${id}/`, data)
  },

  // 删除面试题目
  deleteQuestion(id) {
    return request.delete(`/interviews/questions/${id}/`)
  }
}

// 面试任务相关API
export const interviewTaskApi = {
  // 获取面试任务列表
  getTaskList(params = {}) {
    return request.get('/interviews/tasks/', params)
  },

  // 创建面试任务
  createTask(data) {
    return request.post('/interviews/tasks/', data)
  },

  // 获取面试任务详情
  getTaskDetail(id) {
    return request.get(`/interviews/tasks/${id}/`)
  },

  // 完成面试任务
  completeTask(id) {
    return request.post(`/interviews/tasks/${id}/complete/`)
  }
}

// 面试练习相关API
export const interviewPracticeApi = {
  // 创建练习会话
  createPracticeSession(data) {
    return request.post('/interviews/practice/sessions/', data)
  },

  // 发送消息到dify工作流
  sendMessage(sessionId, data) {
    return request.post(`/interviews/practice/sessions/${sessionId}/messages/`, data)
  },

  // 获取练习会话详情
  getPracticeSession(sessionId) {
    return request.get(`/interviews/practice/sessions/${sessionId}/`)
  },

  // 获取练习会话列表
  getPracticeSessionList(params = {}) {
    return request.get('/interviews/practice/sessions/', params)
  },

  // 结束练习会话
  endPracticeSession(sessionId) {
    return request.post(`/interviews/practice/sessions/${sessionId}/end/`)
  },

  // 获取练习记录
  getPracticeRecords(params = {}) {
    return request.get('/interviews/practice/records/', params)
  },

  // 获取练习记录详情
  getPracticeRecordDetail(recordId) {
    return request.get(`/interviews/practice/records/${recordId}/`)
  }
}

// 其他API
export const interviewOtherApi = {
  // 获取面试统计
  getStatistics() {
    return request.get('/interviews/statistics/')
  },

  // 获取可用老师列表
  getAvailableTeachers() {
    return request.get('/interviews/available-teachers/')
  },

  // 检查过期面试
  checkExpiredInterviews() {
    return request.post('/interviews/check-expired/')
  }
}

// 默认导出所有API
export default {
  application: interviewApplicationApi,
  interview: interviewApi,
  result: interviewResultApi,
  category: interviewCategoryApi,
  question: interviewQuestionApi,
  task: interviewTaskApi,
  other: interviewOtherApi
}
